home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / source14 / rrsqlint.pas < prev   
Pascal/Delphi Source File  |  1995-12-22  |  18KB  |  468 lines

  1. { Demo of interfacing Delphi to a DLL }
  2. { Needs R&R Report Writer - SQL Edition V6.0 - Concentric Data Systems, Inc.}
  3.  
  4. { Borland Delphi Interface Unit To R&R Runtime DLL }
  5. { Author : Chris Brooksbank (cbrooksbank@cix.compulink.co.uk) }
  6. { June 13th 1995 }
  7. { Version 1.1 }
  8.  
  9. { You are free to distribute and use this file as you wish with this header }
  10. { Please email any comments/enhancements to cbrooksbank@cix.compulink.co.uk }
  11.  
  12. unit RRSQLInt;
  13.  
  14. interface
  15.  
  16. uses WinTypes;
  17.  
  18. { ************* Sample code to run a report ************************ }
  19. { ****************************************************************** }
  20.  
  21. { ************* Initialisation and cleanup functions/ run report ******* }
  22. function InitRunTimeInstance: Boolean;
  23.   { You must call this function first. It initialises an instance of the
  24.     R&R runtime DLL }
  25. function EndRunTimeInstance: Boolean;
  26.   { Call this function to cleanup after you have finished using the R&R 
  27.     runtime DLL }
  28. function EndReport(hReport: Integer): Boolean;
  29.   { Free resources allocated to a report. Always call after using a report. }
  30. function  ChooseReport(MyApp,LibName,RepName:PChar;Size: Integer): Integer;
  31.   { Given a report library and report name return a handle to this report.
  32.     Most functions need a hReport param. That is what this function returns.
  33.     If RepName is NIL interactively asks for report from menu }
  34. function  GetNewReportHandle(MyApp: PChar): Integer;
  35.   { Another way of getting a report handle. This is a handle to a empty 
  36.     report information structure. Use ChooseReport in preference to this }
  37. function  execRuntime(hReport:Integer;Wait:Boolean;cmdShow: Integer;
  38.                       ECode: PInteger;PageCount: PLongInt;
  39.                       EMsg:Pchar;Emsgsizeof: Integer): Integer;
  40.    { After getting a report handle and amending any settings call this
  41.      function to actually run the report 
  42.      cmdShow can be sw_hide,sw_minimize,sw_restore,sw_show,sw_showmaximized,
  43.                     sw_showminimized,sw_showminnoactive,sw_showna,
  44.             sw_shownoactive,sw_shownormal 
  45.             ie any Windows API ShowWindow
  46.      on Return Ecode value indicates (Error message in EMsg) :
  47.      Ecode=N Successful execution of report
  48.      Ecode=C User cancelled the report Emsg="Report canceled"
  49.      Ecode=J Report structure pointed to by hReport is incorrect/corrupt
  50.      Ecode=R Report began to execute but failed to complete. }
  51. { ********************************************************************** }
  52.  
  53.  
  54. { ********************************************************************** }
  55. { Getting information about R&R errors }
  56. function GetErrorInfo(Msg:PChar;MsgSize:Integer;ErrCode:PInteger): Boolean;
  57.   { Get error message and code returned by last DLL call }
  58.   { ErrCode can be : 
  59.     C=Cancel. User cancelled a dialog box presented by the R&R DLL 
  60.     D=Diagnostic. Misc. error such as out of memory
  61.     I=Iteration. No more values for requested getfirst or getnext function
  62.     J=Job Control. Problem with specified runtime control file
  63.     L=Library.Problem with report library being accessed
  64.     S=Syntax error.
  65.     V=Value. No value available for specified paramater.}
  66. function resetErrorInfo: Boolean;
  67.   { Clear out the last error message }
  68. { ********************************************************************** }
  69.  
  70.  
  71. { Which page to start printing at }
  72. function  GetBeginPage(hReport: Integer;BeginPage: Plongint): Boolean;
  73. function  SetBeginPage(hReport: Integer;lBeginPage: longint): Boolean;
  74.  
  75. { Which page to end printing at }
  76. function  GetEndPage(hReport:Integer;EndPage: Plongint): Boolean;
  77. function  SetEndPage(hReport: Integer;EndPage: LongInt): Boolean;
  78.  
  79. { How many copies of report to print }
  80. function  GetCopies(hReport: Integer;Copies: PInteger): Boolean;
  81. function  SetCopies(hReport: Integer;Copies: Integer): Boolean;
  82.  
  83. { Data source for report }
  84. function  ChooseDataSource(hReport:Integer;DataSource:PChar;Size:Integer): Boolean;
  85.   { Interactive choosing by user }
  86. function  SetDataSource(hReport: Integer;DataSource: PChar): Boolean;
  87. function  GetDataSource(hReport: Integer;DataSource: PChar): Boolean;
  88.  
  89. { Should R&R display errors on the screen ? }
  90. function SetDisplayErrors(hReport:Integer;DispErr: Boolean): Boolean;
  91. function GetDisplayErrors(hReport:Integer;DispErr: Pbool): Boolean;
  92.  
  93. { Should R&R display a status window as the report is being generated ? }
  94. function SetDisplayStatus(hReport:Integer;DispStatus: Boolean): Boolean;
  95. function GetDisplayStatus(hReport:Integer;DispStatus:PBool): Boolean;
  96.  
  97. { Export destination }
  98. { D=Display
  99.   F=File
  100.   P=Printer }
  101. function SetExportDest(hReport:Integer;Val: char ): Boolean;
  102. function GetExportDest(hReport:Integer;Val: PChar): Boolean;
  103.  
  104. { View/alter the filter the report will use }
  105. function setFilter(hReport:Integer;Filter: PChar): Boolean;
  106. function getFilter(hReport:Integer;Filter:Pchar;Size:Integer): Boolean;
  107.  
  108. { Which filter to use }
  109. { S=use filter saved with report
  110.   E=dont use any filter. Use entire recordset
  111.   O=Use filter specified with setfilter()
  112.   ?=Allow user to interactively design filter at runtime }
  113. function setFilterUsage(hReport:Integer;Val:Char): Boolean;
  114. function getFilterUsage(hReport:Integer;Val: PChar): Boolean;
  115.  
  116. { get/set the main table to be used in the report }
  117. function setMasterTableName(hReport:Integer;FileName:PChar): Boolean;
  118. function getMasterTableName(hReport:Integer;Filename: PChar;Size: Integer): Boolean;
  119.  
  120. { get/set the ASCII memo file to use in the report }
  121. function setMemoName(hReport:Integer;Path:Pchar): Boolean;
  122. function getMemoName(hReport:Integer;Path:PChar;Size:Integer): Boolean;
  123.  
  124. { get/set the Report output destination }
  125. { D=Display
  126.   A/T=Text File - set by setOutputFile 
  127.   P=Printer
  128.   W=Worksheet File
  129.   X=XBASE file
  130.   ?=Interactive at runtime }
  131. function setOutputDest(hReport:Integer;Dest:Char): Boolean;
  132. function getOutputDest(hReport:Integer;Dest:Pchar): Boolean;
  133.  
  134. { Filename to output report to }
  135. function setOutputFile(hReport:Integer;Name:Pchar): Boolean;
  136. function getOutputFile(hReport:Integer;Name:PChar;Size: Integer): Boolean;
  137.  
  138. { Allow user to interactively select the printer to use }
  139. { can later pass selected name to setPrinter }
  140. function ChoosePrinter(hReport:Integer;Printer:PChar;SizePrinter:Integer;
  141.                    PortName:PChar;SizePort:Integer): Boolean;
  142.  
  143. { Get/set printer name associated with the report }
  144. function getPrinter(hReport:Integer;PrinterName: PChar;Size: Integer): Boolean;
  145. function setPrinter(hReport:Integer;PrinterName: PChar): Boolean;
  146.  
  147. { Set the parent window of the preview window by passing the window handle }
  148. function SetWinParentHandle(hReport:Integer;hParent:Integer): Boolean;
  149.  
  150. { Replace the default data directory specified in RSW.INI }
  151. function SetDataDir(hReport:Integer;Dir:PChar): Boolean;
  152.  
  153. { Get/set functions for group fields }
  154. function GetFirstGroupField(hReport:Integer;Name:PChar;Size:Integer): Boolean;
  155. function GetNextGroupField(hReport:Integer;Name:PChar;Size:Integer):  Boolean;
  156. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  157. function SetGroupField(hReport:Integer;Name:Pchar;GroupNum:Integer): Boolean;
  158. { Need to setgroupfields 1..last one to modify }
  159.  
  160. { Replace the default image directory as stored in RSW.INI }
  161. function SetImageDir(hReport:Integer;Dir:PChar): Boolean;
  162.  
  163. { Get/Set printer port }
  164. function GetPrinterPort(hReport:Integer;PortName:PChar;Size:Integer): Boolean;
  165. function SetPrinterPort(hReport:Integer;Port:PChar): Boolean;
  166.  
  167. { R=User prompted to select a report from current report library
  168.   ?=User prompted to pick a succession of reports }
  169. function GetReportPick(hReport:Integer;Pickflag:PChar): Boolean;
  170. function SetReportPick(hReport:Integer;Pickflag:Char): Boolean;
  171.  
  172. { Functions to get/set sort fields }
  173. function GetFirstSortField(hReport:Integer;Name:PChar;Size:Integer): Boolean;
  174. function GetNextSortField(hReport:Integer;Name:PChar;Size:Integer): Boolean;
  175. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  176. function SetSortField(hReport:Integer;Name:PChar;SortNum:Integer): Boolean;
  177.  
  178. { Get field names available to report }
  179. function GetFirstFieldName(hReport:Integer;FieldName:PChar;FnSize:Integer): Boolean;
  180. function GetNextFieldName(hReport:Integer;FieldName:PChar;Fnsize:Integer): Boolean;
  181. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  182.  
  183. { Allow user to interactively select a table,database and datasource }
  184. function ChooseTable(hReport:Integer;Table:PChar;SizeofTable:Integer;
  185.                   DataSource:PChar;SizeOfDataSource:Integer;
  186.               DataBase:PChar;SizeOfDataBase:Integer): Boolean;
  187.  
  188.  
  189. { Get/set functions for join informations. Main table & related alias name.}
  190. function GetFirstJoinInfo(hReport:Integer;TableName:PChar;
  191.                       TableSize:Integer;Alias:PChar;
  192.               AliasSize:Integer): Boolean;
  193. function GetNextJoinInfo(hReport:Integer;TableName:PChar;
  194.                            TableSize:Integer;Alias:PChar;
  195.              AliasSize:Integer): Boolean;
  196. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  197. function setJoinInfo(hreport:Integer;TableName:PChar;
  198.                  AliasName:PChar;AliasNum:Integer): Boolean;
  199.  
  200.  
  201.  
  202. { Get/set user paramaters }
  203. function GetFirstUserParam(hReport:Integer;PName:PChar;PNameSize:Integer;
  204.                        PValue:PChar;PValueSize:Integer): Boolean;
  205. function GetNextUserParam(hReport:Integer;PName:PChar;PNameSize:Integer;
  206.                        PValue:PChar;PValueSize:Integer): Boolean;
  207. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  208. function SetUserParam(hReport:Integer;Name:PChar;Value:PChar): Boolean;
  209. { To get R&R to ask in a dialog 'Enter Your Name :' then pass a value of
  210.   "?Enter your name:"}
  211.  
  212. { Get/set functions for replaceable parts of SELECT,EXEC or DEFINE REPORTVIEW
  213.   statements. ( Those parts enclosed in <<>> e.g. :
  214.   Select <<'firstname','lastname'>> from students
  215.   where <<'firstname'<'lastname'>>}
  216. function GetFirstReplace(hReport:Integer;Replace:PChar;Size:Integer): Boolean;
  217. function GetNextReplace (hReport:Integer;Replace:PChar;Size:Integer): Boolean;
  218. { GetErrorInfo() returns 'I' in 3rd param when no more in list } 
  219. function SetReplace(hReport:Integer;Replacement:PChar): Boolean;
  220.   { Replacement should be comma-separated list of parameters
  221.     enclosed in double angle brackets :
  222.     <<param1>>,<<param2>>,<<param3>>...<<paramn>>}
  223.  
  224.  
  225. { Should user be allowed to abort report when R&R is generating it by
  226.   clicking on a cancel button ? }
  227. function GetPreventEscape(hReport:Integer;Value:PBool): Boolean;
  228. function SetPreventEscape(hReport:Integer;Value:Boolean): Boolean;
  229.  
  230. { Get/set report library name and directory }
  231. function GetLibrary(hReport:Integer;LibName:PChar;LibNameSize:Integer): Boolean;
  232. function setLibrary(hreport:Integer;LibName:PChar): Boolean;
  233. function setLibraryDir(hReport:Integer;DirName:PChar): Boolean;
  234.  
  235. { Set username and password needed to connect to reports datasource }
  236. function setPassword(hReport:Integer;Password:PChar): Boolean;
  237. function setUserName(hReport:Integer;UserName:PChar): Boolean;
  238.  
  239. { Should user be offered a test pattern before real report is printed ? }
  240. function getTestPattern(hReport:Integer;Value:PBool): Boolean;
  241. function setTestPattern(hReport:Integer;Value:Boolean): Boolean;
  242.  
  243. { Read/write all configurations for current report to a ASCII file }
  244. function getRunTimeRecord(AppName:PChar;Filename:PChar): Integer;
  245. function writeRunTimeRecord(hReport:Integer;FileName:PChar): Boolean;
  246.  
  247. { Should status file be updated after every page or just at report end ? }
  248. { status file only applicable when execRuntime is passed Wait of nonzero}
  249. function getStatusEveryPage(hReport:Integer;Value:PBool):Boolean;
  250. function setStatusEveryPage(hReport:Integer;Value:Boolean):Boolean;
  251. function setStatusFileName(hReport:Integer;FileName:PChar): Boolean;
  252.  
  253. { Specify a where clause for insertion in the SQL statement of#
  254.   the Auto-SQL report specified by hReport . No effect on a user-SQL report }
  255. function SetWhere(hReport:Integer;Where:PChar): Boolean;
  256.  
  257. { Suppress title and summary areas for empty reports ? }
  258. function setSuppressTitle(hReport:Integer;Value:Boolean): Boolean;
  259.  
  260. { Get/set caption for runtime windows displayed by R&R runtime }
  261. function setWinTitle(hReport:Integer;Title:PChar): Boolean;
  262. function getWinTitle(hReport:Integer;Title:Pchar;Size:Integer): Boolean;
  263.  
  264. { Style of print-preview window 
  265.   0=No Border
  266.   1=Fixed size & single line border
  267.   2=User can change size of preview window
  268.   3=Fixed size and double line border }  
  269. function setWinBorderStyle(hReport:Integer;Style:Integer): Boolean;
  270.  
  271. { Should preview window have a control menu ? }
  272. function setWinControlBox(hReport:Integer;ControlBox:Boolean): Boolean;
  273.  
  274. { Get/set dimensions of report preview window }
  275. function setWinTop(hReport,WinTop:Integer): Boolean;
  276. function setWinLeft(hReport,Left:Integer): Boolean;
  277. function setWinWidth(hReport,WinWidth:Integer): Boolean;
  278. function setWinHeight(hReport,Height:Integer): Boolean;
  279.  
  280. { Allow minimize and maximise of preview window ? }
  281. function setWinMaxButton(hReport:Integer;AllowButton:Boolean): Boolean;
  282. function setWinMinButton(hReport:Integer;AllowButton:Boolean): Boolean;
  283.  
  284. implementation
  285.  
  286. { Tell Delphi that all the functions are stored in RSREPORT.DLL }
  287.  
  288. function initRunTimeInstance;
  289.   external 'RSREPORT';
  290. function endRunTimeInstance;
  291.   external 'RSREPORT';
  292. function endReport;
  293.   external 'RSREPORT';
  294. function chooseReport;
  295.   external 'RSREPORT';
  296. function GetNewReportHandle;
  297.   external 'RSREPORT';
  298. function execRunTime;
  299.   external 'RSREPORT';
  300. function GetErrorInfo;
  301.   external 'RSREPORT';
  302. function ResetErrorInfo;
  303.   external 'RSREPORT';
  304. function GetBeginPage;
  305.   external 'RSREPORT';
  306. function SetBeginPage;
  307.   external 'RSREPORT';
  308. function GetEndPage;
  309.   external 'RSREPORT';
  310. function SetEndPage;
  311.   external 'RSREPORT';
  312. function GetCopies;
  313.   external 'RSREPORT';
  314. function SetCopies;
  315.   external 'RSREPORT';
  316. function ChooseDataSource;
  317.   external 'RSREPORT';
  318. function SetDataSource;
  319.   external 'RSREPORT';
  320. function GetDataSource;
  321.   external 'RSREPORT';
  322. function SetDisplayErrors;
  323.   external 'RSREPORT';
  324. function GetDisplayErrors;
  325.   external 'RSREPORT';
  326. function SetDisplayStatus;
  327.   external 'RSREPORT';
  328. function GetDisplayStatus;
  329.   external 'RSREPORT';
  330. function SetExportDest;
  331.   external 'RSREPORT';
  332. function GetExportDest;
  333.   external 'RSREPORT';
  334. function setFilter;
  335.   external 'RSREPORT';
  336. function getFilter;
  337.   external 'RSREPORT';
  338. function setFilterUsage;
  339.   external 'RSREPORT';
  340. function getFilterUsage;
  341.   external 'RSREPORT';
  342. function setMasterTableName;
  343.   external 'RSREPORT';
  344. function getMasterTableName;
  345.   external 'RSREPORT';
  346. function setMemoName;
  347.   external 'RSREPORT';
  348. function getMemoName;
  349.   external 'RSREPORT';
  350. function setOutputDest;
  351.   external 'RSREPORT';
  352. function getOutputDest;
  353.   external 'RSREPORT';
  354. function setOutputFile;
  355.   external 'RSREPORT';
  356. function getOutputFile;
  357.   external 'RSREPORT';
  358. function ChoosePrinter;
  359.   external 'RSREPORT';
  360. function getPrinter;
  361.   external 'RSREPORT';
  362. function setPrinter;
  363.   external 'RSREPORT';
  364. function SetWinParentHandle;
  365.   external 'RSREPORT';
  366. function SetDataDir;
  367.   external 'RSREPORT';
  368. function getFirstGroupField;
  369.   external 'RSREPORT';
  370. function getNextGroupField;
  371.   external 'RSREPORT';
  372. function SetGroupField;
  373.   external 'RSREPORT';
  374. function SetImageDir;
  375.   external 'RSREPORT';
  376. function GetPrinterPort;
  377.   external 'RSREPORT';
  378. function SetPrinterPort;
  379.   external 'RSREPORT';
  380. function GetReportPick;
  381.   external 'RSREPORT';
  382. function SetReportPick;
  383.   external 'RSREPORT';
  384. function GetFirstSortField;
  385.   external 'RSREPORT';
  386. function GetNextSortField;
  387.   external 'RSREPORT';
  388. function SetSortField;
  389.   external 'RSREPORT';
  390. function GetFirstFieldName;
  391.   external 'RSREPORT';
  392. function GetNextFieldName;
  393.   external 'RSREPORT';     
  394. function ChooseTable;
  395.   external 'RSREPORT';
  396. function GetFirstJoinInfo;
  397.   external 'RSREPORT';
  398. function GetNextJoinInfo;
  399.   external 'RSREPORT';
  400. function setJoinInfo;
  401.   external 'RSREPORT';
  402. function GetFirstUserParam;
  403.   external 'RSREPORT';
  404. function GetNextUserParam;
  405.   external 'RSREPORT';
  406. function SetUserParam;
  407.   external 'RSREPORT';
  408. function GetFirstReplace;
  409.   external 'RSREPORT';
  410. function GetNextReplace;
  411.   external 'RSREPORT';
  412. function SetReplace;
  413.   external 'RSREPORT';
  414. function GetPreventEscape;
  415.   external 'RSREPORT';
  416. function SetPreventEscape;
  417.   external 'RSREPORT';
  418. function GetLibrary;
  419.   external 'RSREPORT';
  420. function setLibrary;
  421.   external 'RSREPORT';
  422. function setLibraryDir;
  423.   external 'RSREPORT';
  424. function setPassword;
  425.   external 'RSREPORT';
  426. function setUserName;
  427.   external 'RSREPORT';
  428. function getTestPattern;
  429.   external 'RSREPORT';
  430. function setTestPattern;
  431.   external 'RSREPORT';
  432. function getRunTimeRecord;
  433.   external 'RSREPORT';
  434. function writeRunTimeRecord;
  435.   external 'RSREPORT';
  436. function getStatusEveryPage;
  437.   external 'RSREPORT';
  438. function setStatusEveryPage;
  439.   external 'RSREPORT';
  440. function setStatusFileName;
  441.   external 'RSREPORT';
  442. function SetWhere;
  443.   external 'RSREPORT';
  444. function setSuppressTitle;
  445.   external 'RSREPORT';
  446. function setWinTitle;
  447.   external 'RSREPORT';
  448. function getWinTitle;
  449.   external 'RSREPORT';
  450. function setWinBorderStyle;
  451.   external 'RSREPORT';
  452. function setWinControlBox;
  453.   external 'RSREPORT';
  454. function setWinTop;
  455.   external 'RSREPORT';
  456. function setWinLeft;
  457.   external 'RSREPORT';
  458. function setWinWidth;
  459.   external 'RSREPORT';
  460. function setWinHeight;
  461.   external 'RSREPORT';
  462. function setWinMaxButton;
  463.   external 'RSREPORT';
  464. function setWinMinButton;
  465.   external 'RSREPORT';
  466.  
  467. end.
  468.